package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CollegesAddDTO;
import org.jsola.hr.dto.CollegesUpdateDTO;
import org.jsola.hr.entity.CollegesDO;
import org.jsola.hr.query.CollegesQuery;
import org.jsola.hr.service.ICollegesService;
import org.jsola.hr.vo.CollegesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 卫人云-院校
 *
 * @author zhr
 */
@Component
public class CollegesTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICollegesService collegesService;

    /**
     * 生成add测试数据
     * @return CollegesAddDTO
     */
    public CollegesAddDTO getCollegesAddDTO(){
        CollegesAddDTO collegesAddDTO = new CollegesAddDTO();
        collegesAddDTO.setName(getRandomValue("varchar",50));
        collegesAddDTO.setIsTalentBase(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        collegesAddDTO.setCity(getRandomValue("varchar",50));
        collegesAddDTO.setAdminName(getRandomValue("varchar",50));
        collegesAddDTO.setAdminUserId(getRandomValue("varchar",32));
        collegesAddDTO.setContactNumber(getRandomValue("varchar",11));
        return collegesAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CollegesUpdateDTO
     */
    public CollegesUpdateDTO getCollegesUpdateDTO(CollegesVO collegesVO){
        return collegesService.selectDOById(collegesVO.getId(), SITE_ID).to(CollegesUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CollegesQuery
     */
    public CollegesQuery getCollegesQuery() {
        CollegesQuery collegesQuery = new CollegesQuery();
        List<CollegesDO> collegesDOList = collegesService.list(new CollegesDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(collegesDOList)) {
            CollegesDO collegesDO = collegesDOList.get(0);
            collegesQuery = collegesDO.to(CollegesQuery.class);
        }
        return collegesQuery;
    }

    /**
     * 保存示例
     * @return CollegesVO
     */
    public CollegesVO saveCollegesExample(){
        CollegesAddDTO addDTO = this.getCollegesAddDTO();
        CollegesVO collegesVO = collegesService.save(addDTO,buildTokenUser());
        return collegesVO;
    }


}

